package com.poller.share;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.poller.share1.R;

public class app1 extends Activity {
	
	public static final String Checked = "isChecked"; 
	public static final String PREF_CONFIG = "pref_config";
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        CheckBox cb = (CheckBox) findViewById(R.id.checkBox);
        cb.setChecked(getChecked());
        cb.setOnCheckedChangeListener(new OnCheckedChangeListener(){
			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				saveResult(isChecked);
			}
        });
    }
    
    private boolean saveResult (boolean isChecked) {
    	SharedPreferences sp = this.getSharedPreferences(PREF_CONFIG, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(Checked, isChecked);
        return editor.commit();
    }
    
    private boolean getChecked () {
    	SharedPreferences sp = this.getSharedPreferences(PREF_CONFIG, Activity.MODE_PRIVATE);
    	return sp.getBoolean(Checked, false);
    }    
    
}